package com.lq.educationsystem.student.controller;


import com.lq.educationsystem.common.entiy.AdminTb;
import com.lq.educationsystem.common.util.Result;
import com.lq.educationsystem.common.util.ResultBuild;
import com.lq.educationsystem.common.util.ResultChange;
import com.lq.educationsystem.common.util.ResultPage;
import com.lq.educationsystem.common.vo.*;
import com.lq.educationsystem.student.entiy.StudentTb;
import com.lq.educationsystem.student.feign.AdminFeign;
import com.lq.educationsystem.student.service.StudentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "学生业务")
@RequestMapping("/student")
@RestController
public class StudentController {

    @Autowired
    StudentService studentService;
    //调用其他微服务

    @Autowired
    AdminFeign adminFeign;

    @Operation(summary = "登录功能")
    @PostMapping("/login")
    public Result studentLogin(@RequestBody StudentLognVo studentLognVo){

        System.out.println(studentLognVo.toString());
        //获取请求
        Result<StudentTb>  studentTbResult =studentService.studentLogn(studentLognVo);
        return studentTbResult;
    }

    @Operation(summary = "feign接口测试")
    @PostMapping("/feign/test")
    public Result studentFeignLogin(){
        //数据导入

//        AdminTb adminTb = ResultChange.changeObject(adminFeign.queryById(1), new AdminTb());
        AdminPageVo adminPageVo = new AdminPageVo();

        adminPageVo.setPage(1);
        adminPageVo.setPageSize(10);

        ResultPage<AdminTb> adminTbResultPage = adminFeign.queryList(adminPageVo);
        java.util.List<AdminTb> data = adminTbResultPage.getData();


        return ResultBuild.buildOk(data);
    }

    //查询数据

    /**
     * 通过学生id查询班级成员
     *
     *
     */
    @Operation(summary = "通过学生id查询学生课程集合")
    @PostMapping("/qcslibs")
    public ResultPage<StudentTb> queryClassesStudentListInfoByStudentId(@RequestBody StudentPageVo studentPageVo){

        //查询数据

        ResultPage<StudentTb> studentInfoList = studentService.queryClassesStudentListInfoByStudentId(studentPageVo);

        return studentInfoList;
    }

    /**
     * 查询学生所在班级课程信息
     */
    @Operation(summary = "查询学生课程信息")
    @PostMapping("/querycsubject")
    public ResultPage<ClassesSubjectTeacherVo> queryStudentSubjectInfo(@RequestBody StudentPageVo studentPageVo){

        ResultPage<ClassesSubjectTeacherVo> queryStudentSubjectInfo = studentService.queryStudentSubjectInfo(studentPageVo);
        return  queryStudentSubjectInfo;
    }
    /**
     * 根据学生id查询考试信息
     */
    @Operation(summary = "根据学生id查询考试信息")
    @PostMapping("/query/student/examination")
    public ResultPage<StudentSubjectExaminationVo> queryStudentExaminationByStudentId(@RequestBody StudentPageVo studentPageVo){
        ResultPage<StudentSubjectExaminationVo> queryStudentExaminationByStudentIdResult = studentService.queryStudentExaminationByStudentId(studentPageVo);

        return queryStudentExaminationByStudentIdResult;
    }


    /**
     * 根据学生id查询课程分数
     *
     */
    @Operation(summary = "根据学生分数查询课程分数")
    @PostMapping("/query/student/score")
    public ResultPage<StudentSubjectScoreVo> queryStudentSubjectScoreByStudentId(@RequestBody StudentPageVo studentPageVo){

        ResultPage<StudentSubjectScoreVo> queryStudentSubjectScoreByStudentIdResult = studentService.queryStudentSubjectScoreByStudentId(studentPageVo);
        return queryStudentSubjectScoreByStudentIdResult;
    }


    //根据学生id集合批量查询学生信息

    @Operation(summary = "根据学生id集合批量查询学生数据")
    @PostMapping("/query/batch/student/info")
    public ResultPage<StudentTb> queryBatchStudentInfoByStudentIdList(@RequestBody List<Integer> studentIdList){
        //通过id查询
        ResultPage<StudentTb> resultPage= studentService.queryBatchStudentInfoByStudentIdList(studentIdList);
        return resultPage;
    }

}
